<template>
    <fieldset>
        <legend>购物车</legend>
        <ul>
            <li v-for="item in cartData" :key="item.id">
                名称：{{ item.title }}-------
                价格：{{ item.price }}-------
                数量: {{ item.count }}-------
                <button @click="decrease(item)">减少</button>
            </li>
        </ul>
    </fieldset>
</template>

<script setup>
import { useCart } from '../../store/cart';
import { useProduct } from '../../store/product';
import { storeToRefs } from 'pinia'
let cartStore = useCart()
let productStore = useProduct()
let { cartData } = storeToRefs(cartStore)
let { productData } = storeToRefs(productStore)

let decrease = function (item) {

    let target = productData.value.find(i =>
        i.id == item.id
    )
    let target2 = cartData.value.find(i => i.id == item.id)

    if (target2) {
        target2.count--
        target.inventory++
    }
    console.log(target2);
}
</script>